package ThreeDayMoreThread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolExample2 {
    public static void main(String[] args) {
        //1.创建一个固定大小的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        //2.提交任务到线程池指向
        for (int i = 0; i < 10; i++) {
            final int worki=i;
    executorService.execute(new Runnable() {
        @Override
        public void run() {
                System.out.println("线程任务"+worki+"正在运行"+Thread.currentThread().getName());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程任务"+worki+"已经结束啦");
        }
    });
        }
        //3.关闭线程池
     executorService.shutdown();
    }
}
